package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.util.StringUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.ApprovalProcess;
import com.zygh.policeasset.service.ApprovalProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/approvalprocess"})
@Api(tags = {"审批流程表"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/ApprovalProcessController.class */
public class ApprovalProcessController {
    @Autowired
    ApprovalProcessService approvalProcessService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object add(@RequestBody ApprovalProcess approvalProcess) {
        if (this.approvalProcessService.insert(approvalProcess) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改")
    public Object update(@RequestBody ApprovalProcess approvalProcess) {
        if (StringUtil.isEmpty(String.valueOf(approvalProcess.getId()))) {
            return new CommonResult().validateFailed("审批步骤配置主键不能为空");
        }
        if (this.approvalProcessService.updateById(approvalProcess) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("查询审批步骤配置")
    public Object findAll() {
        return new CommonResult().success(this.approvalProcessService.findAll());
    }

    @RequestMapping(value = {"/findbycondition"}, method = {RequestMethod.GET})
    @ApiOperation("按流程类别和资产主键查询")
    public Object findByCondition(@RequestParam String assets_id, @RequestParam String assets_type) {
        return this.approvalProcessService.findByCondition(assets_id, assets_type);
    }

    @RequestMapping(value = {"/findprocess"}, method = {RequestMethod.GET})
    @ApiOperation("查询资产记录")
    public Object findProcess(ApprovalProcess approvalProcess) {
        if (StrUtil.isEmpty(String.valueOf(approvalProcess.getAssetsId()))) {
            return new CommonResult().validateFailed("资产Id不能为空");
        }
        if (StrUtil.isEmpty(approvalProcess.getAssetsType())) {
            return new CommonResult().validateFailed("资产类型不能为空");
        }
        return new CommonResult().success(this.approvalProcessService.findProcess(approvalProcess));
    }
}